***Table 3

cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Tables"
clear
log using Table3.txt, text replace

***Main results
clear all
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data"
use LPSU_MainSample_Sep2024, replace
set matsize 10000
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Tables"

***Set of fixed effects
egen sic1year=group(sic1 year)
qui tabulate sic1year, generate(dsic1year)
egen month_post= group(month post)
qui tabulate month_post, generate(dmonth)
qui tabulate year_around_ipo, generate(deventyear) 


***Setting the sample to the IV sample (dropping observations colinear with FEs)
set more off
qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
gen sample_IV=e(sample) 
keep if sample_IV==1
**Dropping firms for which ROA only has one observation
bysort id: egen count=count(year)
drop if count==1 

distinct id

**OLS
set more off
eststo:qui xtreg wroa IPO deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* , fe cluster(id) 
outreg2 using Table_main, keep(IPO) nocons label  word bdec(3) tex(frag) addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, OLS,Instrument,-) replace

***First stage
set more off
eststo:qui xtreg IPO instrument deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*, fe cluster(id) 
test instrument
**This is the Kleibergen-Paap F-test. 
outreg2 using Table_main, keep(instrument) sortvar(IPO instrument placebo_instrument) tex(frag) word bdec(3) nocons label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, First stage,Instrument,-)   addstat("F test model", r(F)) 

 **Placebo first stage
set more off 
eststo:qui xtreg IPO placebo_instrument deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*, fe cluster(id) 
test placebo_instrument
outreg2 using Table_main, keep(placebo_instrument) sortvar(IPO instrument placebo_instrument) tex(frag) word bdec(3) nocons label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, Placebo First stage,Instrument,-) addstat("F test model", r(F))  

 **IV-Second stage
set more off
eststo:qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_main, keep(IPO) sortvar(IPO instrument placebo_instrument) tex(frag) word bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes,Regression, Second stage,Instrument,Pre-IPO ret>0) 
 
**Reduced-form
 set more off
eststo:qui xtreg wroa instrument deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth*, fe cluster(id) 
outreg2 using Table_main, keep(instrument) sortvar(IPO instrument placebo_instrument) tex(frag) word bdec(3) nocons label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, Reduced form,Instrument,-) 
 
**Placebo reduced-form 
set more off
eststo:qui xtreg wroa placebo_instrument deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* ,  fe  cluster(id)   
outreg2 using Table_main, keep(placebo_instrument) sortvar(IPO instrument placebo_instrument) tex(frag) word bdec(3) nocons label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes,Regression, Placebo reduced form,Instrument,-)  

**Note: R^2 does not apply to IV regressions 
esttab,   keep(IPO instrument placebo_instrument) order(IPO instrument placebo_instrument) label se b(%9.3f) se(%9.3f) r2 star(* 0.1 ** 0.05 *** 0.01) addnotes(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, r^2 for IV regression has no interpretation) 
 
 
eststo clear 


cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Tables"
log close
